<?php require_once ADMINVIEWPATH.'admin_header.php'; ?>
<?php require_once ADMINVIEWPATH.'admin_menu.php'; ?>
<style type="text/css">
    .bg_floating{
        position: relative;
        height: 100%;
        display: block;
    }
    .bg_floating:hover{
        background-color:#000;
        opacity:0.4;
        background:url("<?=STATICURL?>img/default.png") no-repeat;
        cursor:pointer;
    }
    .active{
        opacity:0.9;
    }
    .cover_btn {
        background: url("<?=STATICURL?>img/ico.png") no-repeat ;
        display: inline-block;
        position: absolute;
        right: 2px;
        top: 52px;
        width: 23px;        
        height: 23px;       
    }
</style>
<!-- Page Content -->
            <div class="page-content">
                <!-- Page Breadcrumb -->
                <div class="page-breadcrumbs">
                    <ul class="breadcrumb">
                        <li>
                            <i class="fa fa-home"></i>
                            <a href="#">首页</a>
                        </li>
                        <li class="">
                            <a href="/luckydog/company/index">商品编辑</a>
                        </li>
                        <li class="active">
                            <a href="/luckydog/item/index?companyid=<?php echo $companyInfo['companyid']?>"><?php echo $companyInfo['name']?></a>
                        </li>
                    </ul>
                </div>
                <!-- /Page Breadcrumb -->
                <!-- Page Header -->
                <div class="page-header position-relative">
                    <div class="header-title">
                        <p style="font-weight: bolder;font-size: 19px;margin-top: 10px;">
                            <i></i>
                        </p>
                    </div>
                    <!--Header Buttons-->
                    <div class="header-buttons">
                        <a class="sidebar-toggler" href="#">
                            <i class="fa fa-arrows-h"></i>
                        </a>
                        <a class="refresh" id="refresh-toggler" href="">
                            <i class="glyphicon glyphicon-refresh"></i>
                        </a>
                        <a class="fullscreen" id="fullscreen-toggler" href="#">
                            <i class="glyphicon glyphicon-fullscreen"></i>
                        </a>
                    </div>
                    <!--Header Buttons End-->
                </div>
                <!-- /Page Header -->
                <!-- Page Body -->
                <div class="page-body">
                   <form class="form-horizontal" role="form">
                        <div class="row">
                                <div class="col-lg-12">
                                    <div class="widget">
                                        <div class="widget-header bordered-bottom bordered-blue">
                                            <span class="widget-caption">编辑商品</span>
                                        </div>
                                        <div class="widget-body">
                                            <div id="horizontal-form">
                                                <form class="form-horizontal" role="form">
                                                    <div class="row">
                                                        <div class="col-md-6">
                                                            <select class="form-control it_categoryid">
                                                                <option categoryid="0">请选择分类</option>
                                                                <?php foreach($cat_list as $k=>$v):?>
                                                                        <option categoryid="<?=$v['id']?>"  <?php if($itemdetail['categoryid'] == $v['id']):?>selected<?php endif;?>>
                                                                            <?=$v['name']?>
                                                                        </option>
                                                                </option>
                                                                <?php endforeach;?>
                                                            </select>
                                                        </div>
                                                        <div class="col-md-6">
                                                            <input class="form-control it_title" value="<?php echo $itemdetail['title']?>" type="text" placeholder="标题">
                                                            <div class="horizontal-space"></div>
                                                        </div>
                                                        
                                                    </div>
                                                    <div class="row">
                                                        <div class="col-md-6">
                                                            <input class="form-control it_referprice" value="<?php echo $itemdetail['referPrice']?>" type="text" placeholder="参报价：（1000）">
                                                            <div class="horizontal-space"></div>
                                                        </div>
                                                    </div>
                            
                                                    
                                                    <div class="recent-posts" style="float: left">
                                                        <li class="cp_photo_con" style="list-style-type:none;">
                                                            <p ><span  id="J_morepic_upload"></span></p>
                                                        </li>
                                                    </div>
                                                    <div class="widget-content" style="float: right">
                                                        <div class='clearfix' style="margin-top:15px;">
                                                            <label style="margin-top:10px;" class="l">商品封面</label>
                                                            <a class="my_upload_btn J_my_upload_btn"><span id="J_morepic_upload"></span></a>
                                                            
                                                            <?php if(!empty($item_img_list)):?>
                                                            <span id = "picList"  style="position:relative;float:left;margin-left:5px;margin-top:10px;">
                                                            
                                                                <?php foreach ($item_img_list as $key => $row) :?>
                                                                <p style="float:left;margin-right:5px;" data_id="<?=$row['id']?>" class="J_uploadPic" d-original="<?=$row['imgurl']?>">
                                                                    <span class="bg_floating" style="z-index:9999;" class="upload_float"><img  src="/upload/<?=$row['imgurl']?>" width="120px" height="80px"  alt="pic"/>
                                                                        <?php if($row["is_default"]):?><em class="cover_btn J_cover_btn"></em><?php endif;?>
                                                                    </span><br />
                                                                    <a  class="del_pic"  data_id = "<?=$row['id']?>" style="margin-left:40px;" href="javascript:void(0);">删除</a>
                                                                </p>

                                                                <?php endforeach;?>
                                                            <?php else :?>
                                                                <span id = "picList"  style="position:relative;float:left;margin-left:5px">
                                                                    <input type="hidden" name="morepic" id="J_morepic">
                                                                </span>
                                                            <?php endif;?>
                                                                <input type="hidden" name="morepic" id="J_morepic">
                                                            </span>

                                                            <input type="hidden" value="" source_img="" class="J_cover_path"/>
                                                        </div>
                                                    </div>
                                                    <div class="row">
                                                        <div class="col-md-12">
                                                            <label >商品详情</label>
                                                                <textarea class="form-control summary" rows="3" id="summary"  placeholder="summary" style="height:300px;"><?php echo $itemdetail['summary']?></textarea>
                                                            <div class="horizontal-space"></div>
                                                        </div>
                                                    </div>
                                                    <div class="row">
                                                        <div class="col-md-12">
                                                            <label >品牌故事</label>
                                                                <textarea class="form-control historystory" rows="3" id="historystory" name="historystory" placeholder="historystory" style="height:300px;"><?php echo $itemdetail['historystory']?></textarea>
                                                            <div class="horizontal-space"></div>
                                                        </div>
                                                    </div>
                                                    <div>
                                                        <span id="js_submit" class="btn btn-default">提 交</span>
                                                    </div>
                                                </form>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                    </form>
                </div>
            </div>
            <!-- /Page Body -->
        </div>
        <!-- /Page Content -->
<script src="<?= STATICURL; ?>js/jquery.min.js"></script>
<script src="<?php echo STATICURL; ?>layer/layer.js"></script>
<script src="<?= STATICURL; ?>kindeditor/kindeditor.js"></script>
<?php require_once ADMINVIEWPATH.'admin_footer.php'; ?>
<script src="<?php echo STATICURL; ?>js/swfupload.js"></script>
<script src="<?php echo STATICURL; ?>js/swfupload.queue.js"></script>
<script src="<?php echo STATICURL; ?>js/fileprogress.js"></script>
<script src="<?php echo STATICURL; ?>js/handlers.js"></script>
<script>
var options = {
    allowFileManager : true ,         
    //设置编辑器为简单模式
    afterCreate : function() {             
        var self = this;             
        K.ctrl(document, 13, function() {             
            self.sync();             
            K('form[name=myform]')[0].submit();             
        });             
        K.ctrl(self.edit.doc, 13, function() {             
            self.sync();             
            K('form[name=myform]')[0].submit();             
        });             
    }, 
//下面这行代码就是关键的所在,当失去焦点时执行 this.sync();        
    afterBlur:function(){this.sync();},
};
var editor1;
var editor2;
KindEditor.ready(function(K) {
    editor1 = K.create("#summary",options);  
    editor2 = K.create("#historystory",options); 
});
$(".del_pic").live("click",function(){
        var imgsource = $(this).parent().attr("d-original");
        var id = $(this).attr("data_id");
        $.post('/luckydog/item/del_pic', {'imgsource':imgsource,id:id}, function(res) {
            
        });
        $(this).parent().remove();
    });

$(".bg_floating").live("click",function(){
    var tmp_html = '<em class="cover_btn J_cover_btn"></em>';
    $(".cover_btn").remove();           
    $(this).append(tmp_html);
    if($(".bg_floating").hasClass("active")){
        $(".bg_floating").removeClass("active");    
    }
    $(this).addClass("active");
});
$(document).ready(function(){
    $("#js_submit").click(function(){
       // editor.sync();//Js获取值时前面添加
        var categoryid =  $(".it_categoryid").find("option:selected").attr('categoryid');
        var title = $(".it_title").val();
        var summary = $("#summary").val();
        var historystory = $("#historystory").val();
        var referPrice = $(".it_referprice").val();
        if (categoryid == "" || categoryid == 0){
            layer.msg("请选择分类");
            return;
        } 
        if (title == ""){
            layer.msg("标题不能为空");$(".it_title").focus();return;
        }
        
        if (referPrice == ""){
            layer.msg("报价不能为空");$(".it_referprice").focus();return;
        }

        var original_arr = new Array();
        var default_arr = new Array();
        var ids_arr = new Array();
        $(".J_uploadPic").each(function(){
            if($(this).children().hasClass("active")){
                    default_arr.push("1");
            }else{
                default_arr.push("0");
            }
            original_arr.push($(this).attr("d-original"));
            ids_arr.push($(this).attr("data_id"));
        });
        if(original_arr.length<=0){
            layer.msg("请上传商品封面图片");
            return;
        }
        var itemid = "<?php echo $itemdetail['itemid']?>";
        var _execute = "do_add";
        if(itemid != ""){
            _execute = "do_edit";
        }
        $.post("/luckydog/item/"+_execute, {ids_arr:ids_arr,itemid:itemid,categoryid:categoryid,title:title,summary:summary,historystory:historystory,original_arr:original_arr,default_arr:default_arr,referPrice:referPrice}, function(data) {
            console.log(data);
            if (data.status) {
                layer.msg(data.message);
                window.location.href="/luckydog/item";
            }else{
                layer.msg(data.message);
            }
        }, "json");
    });  
});
    $(function(){
        var settings = {
            flash_url : "<?php echo STATICURL; ?>js/swfupload.swf",
            upload_url: "<?=BASEURL?>luckydog/item/upload_cover.json",
            post_params: {"is_more" : "yes"},
            file_size_limit : "100 MB",
            file_types : "*.jpg;*.gif;*.jpeg;*.png;",
            file_upload_limit : 100,
            file_queue_limit : 100,
            custom_settings : {
                progressTarget : "fsUploadProgress",
                cancelButtonId : "btnCancel"
            },
            debug : false,
            // Button settings
            button_width : "114",
            button_height : "32",
            button_placeholder_id : "J_morepic_upload",
            button_text_style : ".theFont { font-size: 16;}",
            button_cursor:-2,
            button_window_mode:"TRANSPARENT",
            button_action:-110,//-110多图片上传，-100但图片上传，-120文件上传
            button_image_url : "<?php echo STATICURL; ?>img/banner_upload_place.png",

            file_queued_handler : fileQueued,
            file_queue_error_handler : fileQueueError,
            file_dialog_complete_handler : fileDialogComplete,
            upload_start_handler : bookCover_uploadStart,
            upload_progress_handler : uploadProgress,
            upload_error_handler : uploadError,
            upload_success_handler : uploadBookCoverSuccess,
            upload_complete_handler : uploadComplete
        };
        swfu = new SWFUpload(settings);
    }())
</script>






